<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑器械</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input id="id" name="id" type="text" hidden="hidden" />
    <div class="layui-form-item">
        <label class="layui-form-label required">器械编号</label>
        <div class="layui-input-block">
            <input type="text" id="kitId" name="kitId" lay-verify="required" lay-reqtext="器械名不能为空" placeholder="请输入器械名" value="" class="layui-input">
            <!--<tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">器械名</label>
        <div class="layui-input-block">
            <input type="text" id="kitName" name="kitName" lay-verify="required" lay-reqtext="器械名不能为空" placeholder="请输入器械名" value="" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">数量</label>
        <div class="layui-input-block">
            <input type="number" id="amount" name="amount" lay-verify="required" lay-reqtext="数量不能为空" placeholder="请输入数量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">存放地点</label>
        <div class="layui-input-block">
            <input type="text" id="storePlace" name="storePlace" lay-verify="required" lay-reqtext="存放地点不能为空" placeholder="请输入密码"  value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">借出数量</label>
        <div class="layui-input-block">
            <input type="text" id="rentNum" name="rentNum" placeholder="请输入借出数量" value="" class="layui-input">
        </div>
    </div>
    <!--<div class="layui-form-item">-->
    <!--<label class="layui-form-label">职业</label>-->
    <!--<div class="layui-input-block">-->
    <!--<input type="text" name="work" placeholder="请输入职业" value="" class="layui-input">-->
    <!--</div>-->
    <!--</div>-->
    <!--<div class="layui-form-item layui-form-text">-->
    <!--<label class="layui-form-label">备注信息</label>-->
    <!--<div class="layui-input-block">-->
    <!--<textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>-->
    <!--</div>-->
    <!--</div>-->

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/utils.js"></script>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        console.log(GetQueryString_new("id"))

        $.ajax({
            type:"GET",
            url:"/sport/kit/findId",
            data:{
                id:GetQueryString_new("id")
            },
            async:false,
            success:function (data) {
                console.log(data);
                $('#id').val(data.id);
                $('#kitId').val(data.kitId);
                $('#kitName').val(data.kitName);
                $('#amount').val(data.amount);
                $('#storePlace').val(data.storePlace);
                $('#rentNum').val(data.rentNum);
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {
                // 关闭弹出层
                layer.close(index);
                $.ajax({
                    type:"get",
                    url:"/sport/kit/update",
                    data:data.field,
                    error:function () {
                        alert("修改失败");
                    },
                    success:function (data) {
                        console.log(data)
                        if (data.code == 0){
                            layer.alert(data.msg,{icon: 6},function () {
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                window.parent.location.reload();//成功后刷新父界面

                            });

                        } else{
                            layer.alert(data.msg, {icon: 6});
                        }

                    }
                });

            });

            return false;
        });

    });
</script>
</body>
</html>